/**
 * @ClassName Offer10I
 * @Description 剑指 Offer 10- I. 斐波那契数列
 * @Author clockTown
 * @Date 2021/8/19 11:10
 * @Version 1.0
 */
class Offer10I {
}

/**
 * dp数组
 */
class Offer10IV0 {
    public int fib(int n) {
        int[] dp = new int[Math.max(2, n + 1)];
        dp[0] = 0;
        dp[1] = 1;
        for (int i = 2; i <= n; i++) {
            dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007;
        }
        return dp[n];
    }
}

/**
 * v0 代码优化
 */
class Offer10IV1 {
    public int fib(int n) {
        int a = 0;
        int b = 1;
        int sum;
        for (int i = 0; i < n; i++) {
            sum = (a + b) % 1000000007;
            a = b;
            b = sum;
        }
        return a;
    }
}